package com.stalkernet;

import android.app.Application;

import com.urbanairship.push.APIDReceiver;
import com.urbanairship.push.AirMail;
import com.urbanairship.push.PushReceiver;

public class Stalkernet extends Application {
	private static String apid=null;
	private static int userid=-1;
	private static int roomid=-1; 
	
	public static String getAPID()
	{
		return apid;
	}
	
	public static int getUserid() {
		return userid;
	}

	public static void setUserid(int userid) {
		Stalkernet.userid = userid;
	}
	
	public static void setRoomid(int roomid) {
		Stalkernet.roomid = roomid;
	}

	public static int getRoomid() {
		return roomid;
	}


	@Override
	public void onCreate() {
		super.onCreate();

        AirMail am = AirMail.getInstance();
        am.acceptPush(this, new MyPushReceiver());
        am.setAPIDReceiver(this, new MyAPIDReceiver());
	}
	

	class MyPushReceiver implements PushReceiver
	{

		@Override
		public void onClick(String arg0, String arg1) {
			StalkernetBase.d("push", "onClick");

		}

		@Override
		public void onReceive(String key, String payload) {
			StalkernetBase.d("push", "onReceive");
			StalkernetBase.t(Stalkernet.this, "push:onReceive");

		}
	}
	class MyAPIDReceiver implements APIDReceiver
	{

		@Override
        public void onAirMailInstallRefusal() {
            StalkernetManager.am_register = false;
            StalkernetBase.d("push", "AirMail Install Refused!");
        }

		@Override
	    public void onReceive(String apid, boolean valid){
            if(valid){
                StalkernetBase.d("apid push", "Got apid: " + apid);
                Stalkernet.this.apid = apid;
                StalkernetBase.t(Stalkernet.this, "Got apid: " + apid);

            } else {
                StalkernetBase.d("apid push", "Application registration invalid!");
            }
        }
		
	}
}
